using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using T2.WebSecurity.Data.Controllers.Interfaces;
using T2.WebSecurity.Data.Entities.Interfaces;
using T2.WebSecurity.Business.Entities.Interfaces;
using T2.WebSecurity.Business.Entities;
using T2.WebSecurity.Business.Builders;
using T2.WebSecurity.Business.Directors.Interface;
using T2.WebSecurity.Business.Entities.Search.Interfaces;

//--Change Management Control - ApplicationRoles Director  --**********************
//--Created By: trooks
//--Description: ApplicationRoles Director Class
//--Created Date: 03/07/2013 10:48:46
//--*************************************************************

namespace T2.WebSecurity.Business.Directors
{
	public partial class ApplicationRoles_Director_biz : IApplicationRoles_director_biz
	{
		
		public List<IApplicationRoles_biz> Construct (IApplicationRoles_biz _param, bool BuildUp, bool BuildDown)
		{
			ApplicationRoles_Builder build = new ApplicationRoles_Builder();
			List<IApplicationRoles_biz> retVal = build.BuildParts(_param);
			foreach(IApplicationRoles_biz item in retVal)
			{
				item.Application = BuildApplication(item, BuildUp, false);
				item.UsersInRoles_List = BuildUsersInRolesList(item, false, BuildDown);
		}
			return retVal;
		}
		public List<IApplicationRoles_biz> Construct (IApplicationRolesSearch_biz _param, bool BuildUp, bool BuildDown)
		{
			ApplicationRoles_Builder build = new ApplicationRoles_Builder();
			List<IApplicationRoles_biz> retVal = build.BuildParts(_param);
			foreach(IApplicationRoles_biz item in retVal)
			{
				item.Application = BuildApplication(item, BuildUp, false);
				item.UsersInRoles_List = BuildUsersInRolesList(item, false, BuildDown);
		}
			return retVal;
		}
		private IApplication_biz BuildApplication(IApplicationRoles_biz _param, bool BuildUp, bool BuildDown)
		{
			IApplication_biz retVal = new Application_biz();
			if(BuildUp)
			{
			IApplication_biz ApplicationParam = new Application_biz();
			ApplicationParam.Action = "GetOne";
			ApplicationParam.ApplicationID = _param.ApplicationID;
			Application_Builder builder = new Application_Builder();
			retVal = builder.BuildParts(ApplicationParam).First();
			}
			return retVal;
		}
		private List<IUsersInRoles_biz> BuildUsersInRolesList(IApplicationRoles_biz _param, bool BuildUp, bool BuildDown)
		{
			List<IUsersInRoles_biz> retVal = new List<IUsersInRoles_biz>();
			if(BuildDown)
			{
			IUsersInRoles_biz UsersInRolesParam = new UsersInRoles_biz();
			UsersInRolesParam.Action ="ApplicationRoles_UsersInRoles_ByParent";
			UsersInRolesParam.PageNumber = 1;
			UsersInRolesParam.PageSize = 100;
			UsersInRolesParam.SortType = "asc";
			UsersInRolesParam.SortColumn = "UsersInRoleID";
			UsersInRolesParam.ApplicationRoleId = _param.ApplicationRoleId;
			UsersInRoles_Builder builder = new UsersInRoles_Builder();
			retVal = builder.BuildParts(UsersInRolesParam);
			}
			return retVal;
		}
	}
}